package com.cxp.serverdemo.Repository;

import com.cxp.serverdemo.bean.sys.bean.Role;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface RoleRepository extends JpaRepository<Role,Long> {

    @Query("select r from Role r,User u,UserRole ur where r.id=ur.rid and u.id=ur.uid and u.username=:username")
    List<Role> findRolesByUsername(@Param("username") String username);

    @Query("select r from Role r,MenuRole mr where r.id=mr.rid and mr.mid=:mid")
    List<Role> findRolesByMenuId(@Param("mid") Long mid);
}
